package com.gy.bearhelps.setting;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.gy.bearhelps.R;
import com.gy.bearhelps.base.BaseActivity;
import com.gy.bearhelps.setting.adapter.FontAdapter;
import com.gy.bearhelps.util.SharedPrefUtil;

/**
 * 作者：gy on 16/11/5
 * 说明：
 */
public class SetFontActivity extends BaseActivity {

    private ListView listView;
    private FontAdapter adapter;
    private String[] strs = new String[]{"巨无霸","巨大","超大","大","中","小"};
    private String strFont;

    @Override
    protected void initView() {
        setContentViewRes(R.layout.activity_set_font);
        setTitleMsg("设置");
        listView = (ListView) findViewById(R.id.activity_set_font_listview);
    }

    @Override
    protected void initData() {
        adapter = new FontAdapter(this,strs);
        strFont = SharedPrefUtil.get("font","");
        for (int i = 0; i < strs.length; i++) {
            if(strs[i].equals(strFont)){
                adapter.setSelect(i);
                break;
            }
        }
    }

    @Override
    protected void setListener() {
        super.setListener();
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                adapter.setSelect(i);
                adapter.notifyDataSetChanged();
                Intent intent = new Intent();
                intent.putExtra("font",strs[i]);
                SetFontActivity.this.setResult(SettingMainActivity.SETTING_FONT,intent);
            }
        });
    }

    @Override
    protected void fillData() {
        super.fillData();
        listView.setAdapter(adapter);
    }
}
